import 'package:flutter/material.dart';
import 'package:my_shop/load_my_goods.dart';
import 'package:my_shop/widget/quantity_dialog.dart';

typedef OnSelectChanged<T, A> = void Function(T value, A value1);

class GZXOrderWidget extends StatelessWidget {
  const GZXOrderWidget({
    Key? key,
    required this.orderModel,
    required this.addTap,
    required this.removeTap,
    required this.updateValueChanged,
    required this.onSelectChanged,
    required this.isEdit,
  }) : super(key: key);
  final GoodModel orderModel;
  final ValueChanged<int> addTap;
  final ValueChanged<int> removeTap;
  final ValueChanged<String> updateValueChanged;
  final OnSelectChanged<GoodModel, bool> onSelectChanged;
  final bool isEdit;

  @override
  Widget build(BuildContext context) {
    final row = Row(children: <Widget>[
      Row(
        children: <Widget>[
          Row(
            children: [
              const SizedBox(
                height: 16,
              ),
              SizedBox(
                height: 80,
                child: Checkbox(
                  onChanged: (value) {
                    onSelectChanged(orderModel, value ?? false);
                  },
                  value: orderModel.isSelected ?? false,
                  checkColor: Colors.white,
                  activeColor:const Color(0xFFFF8400),
                ),
              ),
              const SizedBox(
                width: 12,
              )
            ],
          ),
          Container(
            width: 80,
            height: 80,
            decoration: BoxDecoration(
              border: Border.all(
                color: const Color(0xFFE6E6E6),
              ),
              borderRadius: const BorderRadius.all(Radius.circular(4)),
            ),
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(4)),
              child: Image.asset(
                orderModel.localUrl ?? '',
                fit: BoxFit.fill,
              ),
            ),
          ),
        ],
      ),
      const SizedBox(
        height: 8,
      ),
      Expanded(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              orderModel.goodName ?? '',
              maxLines: 2,
              style: const TextStyle(fontSize: 14, color: Color(0xFF333333)),
              overflow: TextOverflow.ellipsis,
            ),
            const SizedBox(
              width: 5,
            ),
            const SizedBox(
              height: 10,
            ),
            Row(
              children: [
                Expanded(
                  child: Wrap(
                    crossAxisAlignment: WrapCrossAlignment.center,
                    children: [
                      Text(
                        '\$ ${(orderModel.price ?? 0.0)}',
                        style: const TextStyle(
                          fontSize: 16,
                          color: Color(0xFFF95757),
                          fontWeight: FontWeight.bold,
                        ),
                        overflow: TextOverflow.ellipsis,
                      ),
                      const SizedBox(
                        width: 5,
                      ),
                      Offstage(
                        offstage: orderModel.marketPrice == null,
                        child: Text(
                          '\$ ${(orderModel.marketPrice ?? 0.0)}',
                          style: const TextStyle(
                            color: Color(0xFF999999),
                            fontSize: 12,
                            decoration: TextDecoration.lineThrough,
                            decorationColor: Color(0xFF999999),
                            decorationThickness: 1,
                          ),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  alignment: Alignment.centerRight,
                  child: GZXQuantityDialogWidget(
                    quantity: orderModel.num ?? 0,
                    addTap: addTap,
                    removeTap: removeTap,
                    updateValueChanged: updateValueChanged,
                  ),
                  // ),
                )
              ],
            ),
          ],
        ),
      )
    ]);

    return Column(
      children: [
        Container(
          padding: const EdgeInsets.only(top: 16, right: 16),
          color: Colors.white,
          child: Column(
            children: [
              row,
              const SizedBox(
                height: 16,
              ),
              const Divider(
                height: 1,
                color: Color(0xFFF2F2F2),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
